var prefix = api + "/admin/dict/item";
var systemFlag = getQueryString('flag')
var type = getQueryString('type')
var dictId = getQueryString('id')

$(function() {
	var addFlag = permissions.sys_dict_add
	var editFlag = permissions.sys_dict_edit
	var deleteFlag = permissions.sys_dict_del
	//没有新增权限的话删除新增按钮
	if (systemFlag == 1 || !addFlag) {
		$('#addBtn').remove()
	}
	var options = {
		url : prefix + "/page?dictId="+dictId,
		updateUrl: "/pages/sysadm/dict/dictItemEdit",
        removeUrl: prefix + "/{id}",
		sortName : "create_time",
		sortOrder : "desc",
		modalName : "字典数据",
		columns : [
				{
		            title: "序号",
		            formatter: function (value, row, index) {
		         	    return $.table.serialNumber(index);
		            }
		        },
				{
					field : 'type',
					title : '类型'
				},
				{
					field : 'value',
					title : '数据值'
				},
				{
					field: 'label',
					title: '标签名'
				},
				{
					field: 'description',
					title: '描述'
				},
				{
					field: 'sort',
					title: '排序'
				},
				{
					field : 'remarks',
					title : '备注信息'
				},
				{
					title : '操作',
					align : 'center',
					formatter: function(value, row, index) {
		                var actions = [];
						if(systemFlag != 1){
							if (editFlag) {
								actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
							}
							if (deleteFlag) {
								actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
							}
						}
						return actions.join('');
		            }
				} ]
	};
	$.table.init(options);
});

/*字典数据-新增字典*/
function add() {
    // $.operate.add(dictId);
	$.modal.open("添加字典数据",  "/pages/sysadm/dict/dictItemEdit?oper=add&pid=" + dictId+"&type="+type);
}